<template>
	<scroll-view class="managerCarType">
		<!-- 系统保存的地址数据渲染 -->
		<view class="managerCarType-all">
			<view class="type" v-for="item in lovaCarAll" :key="item.mycarId">
				<view class="typeImage">
					<image :src="item.mycarImage"></image>
				</view>
				<view class="typelist" @click="changeManageCar(item)">
					<view>
						<text class="name">{{item.mycarBrand}}</text>
						<text class="call">{{item.mycarProductionDate}}-{{item.mycarType}}</text>
					</view>
					
				</view>
				<view class="modify">
						<text @click="delMyLoveCarOne(item.mycarId,item.userId)">删除</text>
				</view>
			</view>
		</view>
		<view class="addType">
			<navigator url="../addMyLoveCar/addMyLoveCar">
				<text>添加我的爱车</text>
			</navigator>
		</view>
	</scroll-view>
</template>

<script>
	import {createNamespacedHelpers} from "vuex"
	let {mapActions,mapState}=createNamespacedHelpers("mineCar")
	export default {
		data() {
			return {
				
			};
		},
		// created() {
		// }
		onLoad() {
			this.getMyLoveCarAll();
		},
		computed:{
			...mapState(["lovaCarAll"])
		},
		methods:{
			// 删除
			...mapActions(["getMyLoveCarAll","delMyLoveCar"]),
			async delMyLoveCarOne(mycarId,userId){
				let data =await this.delMyLoveCar({mycarId,userId})
				if(data.code==1338){
					uni.showToast({
						title:"删除爱车成功"
					})
					this.getMyLoveCarAll();
					if(this.lovaCarAll.length==1){
						uni.redirectTo({
							url:"../mine"
						})
					}
				}
			},
			// changeManageCar(var){
			// 	console.log(var)
			// }
			changeManageCar(item){
				uni.setStorageSync('loveCar',JSON.stringify(item))
				uni.navigateTo({
					url:'../loveCar/loveCar'
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.managerCarType{
		height: 100vh;
		padding: 12rpx;
		background-color: #f5f5f5;
		box-sizing: border-box;
		position: relative;
		.managerCarType-all{
			margin-top: 20rpx;
			.type{
				width: 100%;
				background-color: #ffffff;
				border-radius: 10rpx;
				display: flex;
				box-sizing: border-box;
				padding: 10rpx;
				.typeImage{
					width: 15%;
					height: 160rpx;
					display: flex;
					align-items: center;
					image{
						width: 95%;
						height: 90rpx;
					}
				}
				.typelist{
					box-sizing: border-box;
					padding: 10rpx;
					margin-top: 50rpx;
					width: 75%;
					view{
						&:nth-of-type(1){
							margin-bottom: 10rpx;
							.name{
								font-weight: bold;
								opacity: 0.8;
								font-size: 30rpx;
								margin-right: 20rpx;
							}
							.call{
								color: #555555;
								opacity: 0.8;
								font-size: 26rpx;
							}
							
						}
					}
					
				}
				.modify{
					width: 15%;
					font-size: 28rpx;
					color: #b3b2b6;
					display: flex;
					align-items: center;
					text{
						width: 80rpx;
						line-height: 60rpx;
						padding-left: 20rpx;
						height: 60rpx;
						display: inline-block;
						border-left: 1rpx solid  #c4c3c7;
					}
				}
			}
		}
		.addType{
			width: 100vw;
			height: 100rpx;
			background-color: white;
			position: absolute;
			bottom: 0rpx;
			line-height: 100rpx;
			text-align: center;
			color: tomato;
			font-size: 34rpx;
			font-weight: bold;
		}
	}

</style>
